<div class="layui-form layui-row" lay-filter="form_notice">
  <script type="text/html" template lay-done="layui.data.done(d.params)">
    <div class="layui-card-body layui-row layui-col-space10">

      <div class="layui-form-item">
        <label class="layui-form-label">公告标题</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" lay-verify="required" name="title"
                 value="{{d.params.title || ''}}">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">封面图</label>
        <div class="layui-input-block">
          <div id="cover_image"></div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">发布时间</label>
        <div class="layui-input-inline">
          <input type="hidden" name="id" value="{{ d.params.id || ''}}">
          <input type="text" id="publish_time" class="layui-input" name="publish_time" placeholder="定时发布时间"
                 autocomplete="off" value="{{d.params.publish_time || ''}}">
        </div>
        <div class="layui-inline">
          <div class="layui-form-mid layui-word-aux">
            不填则提交后马上发布
          </div>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label form-required">公告内容</label>
        <div class="layui-input-inline" style="width: 600px">
          <div id="content">
            {{d.params.content || ''}}
          </div>
        </div>
      </div>

      <div class="layui-card-body layui-row layui-col-space10">
        <div class="layui-col-md6">
          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
              <a class="layui-btn" lay-submit lay-filter="submit_notice">保存</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </script>
</div>

<script>
  layui.data.done = function (obj) {

    layui.use(['fox_upload', 'laydate', 'wangEditor'], function () {
      let $ = layui.$
        , admin = layui.admin
        , fox_upload = layui.fox_upload
        , laydate = layui.laydate
        , editor = layui.wangEditor

      //日历初始化
      laydate.render({
        elem: '#publish_time'
        , type: 'datetime'
      });

      fox_upload.render({
        elem: '#cover_image'
        , name: 'cover_image_url'
        , url: 'agent-admin/notices/image'
        , text: '上传封面图'
        , value: obj.cover_image_url || ''
        , headers: {
          Authorization: admin.getAccessToken('Bearer'),
        }
      })

      //编辑器
      editor.render({
        elem: "#content"
        , height: 500
        , name: 'content'
        , url: 'editor/images'
      });
    })
  }
</script>
